package com.rico.kok.service;

import com.rico.kok.entity.Collection_;
import com.rico.kok.entity.Post;
import com.rico.kok.mapper.CollectionMapper;
import com.rico.kok.mapper.PostMapper;
import com.rico.kok.service.interf.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CollectionServiceImpl implements CollectionService {

    @Autowired
    private CollectionMapper collectionMapper;

    @Autowired
    private PostMapper postMapper;

    //收藏
    @Override
    @Transactional
    public int postCollection(Post post) {
        collectionMapper.collection(post);
        post.setPostCollection(1);
        return postMapper.updatePostCollection(post);
    }

    //取消收藏
    @Override
    public int unCollection(Post post) {
        collectionMapper.unCollection(post);
        post.setPostCollection(0);
        return postMapper.updatePostCollection(post);
    }

    //判定是否收藏
    @Override
    public Integer isCollection(Post post) {
        return collectionMapper.isCollection(post);
    }

    //收藏列表
    @Override
    public List<Collection_> collectionList(int userId) {
        return collectionMapper.collectionList(userId);
    }


}
